//
//  AppDelegate.m
//  Test
//
//  Created by 顾纯晟 on 15/7/10.
//  Copyright (c) 2015年 g & w.com. All rights reserved.
//

#import "AppDelegate.h"
#import "XGPush.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

//ggdhouasiojdijpk
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    [XGPush startApp:2200130992 appKey:@"IEP5843NFU5R"];
    //判断当前版本
    //如果是iOS8.0,我们就是用iOS8.0方法
    if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0)
    {
        UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound categories:nil];
        //iOS8 以后远程通知改为以下方法
        [application registerUserNotificationSettings:setting];
    }else
    {
        //低于iOS8.0版本
        //注册一个远程通知
        //这个远程通知包含的一些服务有"提醒"Alert ,"声音"sound ,"badge"角标
        [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound];
    }
    
    return YES;
}
/**
 *  djakdadjlaj
 *   的发个梵蒂冈
 *  @param application 你好啊打发士大夫
 *  @param deviceToken 大发牢骚的恢复
 */
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    [XGPush registerDevice:deviceToken];
    NSLog(@"%@",[[XGPush registerDevice:deviceToken] description]);
}
//向APNS发送请求
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    //注册我们的远程通知
    [application registerForRemoteNotifications];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
        [application setApplicationIconBadgeNumber:0];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
